var Action = require("../apiaction");
var DataProxy = require("data-proxy");
var httpconf=require('../../node_modules/data-proxy/lib/httpconf.js');
var Utility = require("../Utility/utility.js");

exports.pteRouter = function(router){
//课程列表
    router.all('/pte/api/course',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var sequence = req.param('sequence');
        var course_name = req.param('course_name');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(sequence&&sequence!='undefined')
            param.sequence=sequence;
        if(course_name&&course_name!='undefined')
            param.course_name=course_name;

        Action.send(req,res,'rCourse',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });
    router.get('/pte/lecture',function(req,res){
        var course_id = req.param('course_id');
        var course_name = req.param('course_name');
        var cover = req.param('cover');
        var sequence = req.param('sequence');
        res.render('pte/course/lecture', {
            layout: 'pte/layout-pte',
            active: 'lecturelist',
            jscript: 'pte/course/lecture',
            course_id: course_id,
            course_name:course_name,
            cover:cover,
            sequence:sequence
        })

    });

    //课时列表
    router.all('/pte/api/lecture',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var course_id = req.param('course_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(course_id&&course_id!='undefined')
            param.course_id=course_id;

        Action.send(req,res,'rLecture',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });

    //修改课时
    router.get('/pte/editlecture',function(req,res){
        var lecture_id = req.param("lecture_id");

        Action.send(req,res,'rTeacher',{},function(res,data) {
            teachers=JSON.parse(data);
            Action.send(req,res,'rLecture',{lecture_id:lecture_id},function(res,data){
                var json = JSON.parse(data);
                var detail = json.data;
                detail.min=parseInt(detail.last/60);
                detail.sec=detail.last%60;
                if(detail.video_url)
                    detail.video_url=detail.video_url.replace("http://pteimg.b0.upaiyun.com/video/","")
                res.render ('pte/course/editlecture',{
                    layout:'pte/layout-pte',
                    active:'editcourse',
                    jscript:'pte/course/editlecture',
                    data:detail,
                    teachers:teachers.data.rows
                });
            })
        });
    });

    //新增课时
    router.get('/pte/addlecture',function(req,res){
        var course_id = req.param("course_id");
        var course_name = req.param("course_name");
        var cover = req.param("cover");
        var sequence = req.param("sequence");
        Action.send(req,res,'rTeacher',{},function(res,data) {
            data=JSON.parse(data);
            res.render('pte/course/addlecture', {
                layout: 'pte/layout-pte',
                active: 'addlecture',
                jscript: 'pte/course/addlecture',
                course_id: course_id,
                course_name: course_name,
                cover: cover,
                sequence: sequence,
                teachers:data.data.rows
            })
        });
    });

    router.get('/pte/course',function(req,res){
        //
        res.render('pte/course/course', {
            layout: 'pte/layout-pte',
            active: 'courselist',
            jscript: 'pte/course/course'
        })

    });
    //新增课程
    router.get('/pte/addcourse',function(req,res){
        Action.send(req,res,'rmajor',{},function(res,data){
            var json=JSON.parse(data);
            var acts=json.data;
            res.render ('pte/course/addcourse',{
                layout:'pte/layout-pte',
                active:'addcourse',
                jscript:'pte/course/addcourse',
                acts:acts.rows
            })
        })
    });


    //修改课程
    router.get('/pte/editcourse',function(req,res){
        var course_id = req.param("course_id");
        Action.send(req,res,'rCourse',{course_id:course_id},function(res,data){
            var json = JSON.parse(data);
            var detail = json.data;
            Action.send(req,res,'rmajor',{},function(res,data){
                var acts = JSON.parse(data).data;
                res.render ('pte/course/editcourse',{
                    layout:'pte/layout-pte',
                    active:'editcourse',
                    jscript:'pte/course/editcourse',
                    data:detail,
                    acts:acts.rows
                });
            });
        })

    });
//课程计划表
    router.get('/pte/course-plan',function(req,res){
        res.render('pte/course/cor-plan', {
            layout: 'pte/layout-pte',
            active: 'plan',
            jscript: 'pte/course/cor-plan'
        });
    });
//课程老师
    router.get('/pte/course-teacher',function(req,res){
        res.render('pte/course/cor-tea', {
            layout: 'pte/layout-pte',
            active: 'teacher',
            jscript: 'pte/course/cor-tea'
        });
    });
//课时介绍
    router.get('/pte/course-introduce',function(req,res){
        res.render('pte/course/time-intro', {
            layout: 'pte/layout-pte',
            active: 'introduce',
            jscript: 'pte/course/time-intro'
        });
    });
//课时案例
    router.get('/pte/course-case',function(req,res){
        res.render('pte/course/time-case', {
            layout: 'pte/layout-pte',
            active: 'case',
            jscript: 'pte/course/time-case'
        });
    });
//课时评论
    router.get('/pte/course-comment',function(req,res){
        res.render('pte/course/time-comm', {
            layout: 'pte/layout-pte',
            active: 'comment',
            jscript: 'pte/course/time-comm'
        });
    });
//课时视频
    router.get('/pte/course-movie',function(req,res){
        res.render('pte/course/time-movie', {
            layout: 'pte/layout-pte',
            active: 'movie',
            jscript: 'pte/course/time-movie'
        });
    });
//课时测试
    router.all('/pte/api/course-test',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var course_id = req.param('course_id');
        var lecture_id = req.param('lecture_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows,course_id:course_id,lecture_id:lecture_id};
        if(course_id&&course_id!='undefined')
            param.course_id=course_id;
        if(lecture_id&&lecture_id!='undefined')
            param.lecture_id=lecture_id;
        Action.send(req,res,'rJoint',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });

    router.get('/pte/course-test',function(req,res){
        var course_id = req.param('course_id');
        var lecture_id = req.param('lecture_id');
        res.render('pte/course/time-test', {
            layout: 'pte/layout-pte',
            active: 'test',
            jscript: 'pte/course/time-test',
            course_id:course_id,
            lecture_id:lecture_id
        });
    });
//新增课时测试

    router.all('/pte/api/addtime-test',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var course_id = req.param('course_id');

        var type = req.param('type');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows,course_id:course_id,type:type};
        if(course_id&&course_id!='undefined') {
            param.course_id = course_id;
            //    Action.send(req, res, 'sCitiao', param, function (res, data) {
            //
            //        var json = JSON.parse(data);
            //        if (json.code == 0) {
            //            res.status(200).send(JSON.stringify(json));
            //        } else {
            //            res.status(200).send(data);
            //        }
            //    })
            //}else {
            Action.send(req, res, 'rQuestion', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }

    });
    router.get('/pte/addtime-test',function(req,res){
            var acts = ['判断','单选','多选'];
            var course_id = req.param('course_id');
            var lecture_id = req.param('lecture_id');
            console.log('测试123',course_id);
            res.render ('pte/course/addtime-test',{
                layout:'pte/layout-pte',
                active:'addcourse',
                jscript:'pte/course/addtime-test',
                acts:acts,
                course_id:course_id,
                lecture_id:lecture_id
            })
    });
//修改课时测试
    router.get('/pte/update_time-test',function(req,res){
        var acts = ['判断','单选','多选'];
        var course_id=req.param("course_id");
        var lecture_id = req.param("lecture_id");
        var joint_id = req.param("joint_id");
        var param={course_id:course_id,lecture_id:lecture_id,joint_id:joint_id};
        console.log(param);
        Action.send(req,res,'rJoint',param,function(res,data){
            console.log("节点数据",data);
            data=JSON.parse(data);
            var min = parseInt(data.data.time/60);
            var sec = data.data.time%60;
            if (min<10) {
                min = '0' + min;
                if (min < 1)
                    min = '00';
            }
            if (sec<10) {
                sec = '0' + sec;
                if (sec < 1)
                    sec = '00';
            }
            console.log("时间",data.data.time);
            res.render('pte/course/edittime-test', {
                layout: 'pte/layout-pte',
                active: 'edittime-test',
                jscript: 'pte/course/edittime-test',
                acts:acts,
                min:min,
                sec:sec,
                question:data.data.question,
                lecture_id:lecture_id,
                course_id:course_id,
                joint_id:joint_id
            });
        });
    });

//题库列表
    router.all('/pte/api/question',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var type = req.param('type');
        var title = req.param('title');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(type&&type!='undefined')
            param.type=type;
        if(title&&title!='undefined')
            param.title=title;
        Action.send(req,res,'rQuestion',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });
    router.get('/pte/question',function(req,res){
        res.render('pte/question/question', {
            layout: 'pte/layout-pte',
            active: 'qusestionlist',
            jscript: 'pte/question/question'
        });
    });
    //新增题库
    router.get('/pte/addquestion',function(req,res){
        Action.send(req,res,'rCourse', function (res, data) {
            var json = JSON.parse(data);
            var data = json.data;
            var msg=req.param("msg");
            var host=req.headers["host"];
            if(host.indexOf("zjadmin")!=-1)//server
                var uploadPath="http://121.40.55.132:8082"+httpconf.root+"/question/upload";
            else
                var uploadPath="http://127.0.0.1:8080"+httpconf.root+"/question/upload";
            res.render ('pte/question/addquestion',{
                layout:'pte/layout-pte',
                active:'addquestion',
                jscript:'pte/question/addquestion',
                uploadPath:uploadPath,
                data:data.rows,
                msg:msg
            });
        })
    });
    //修改题库
    router.get('/pte/editquestion',function(req,res){
        var question_id = req.param("question_id");
        Action.send(req,res,'rQuestion',{question_id:question_id},function (res, data) {
            var json = JSON.parse(data);
            var detail = json.data;
            Action.send(req,res,'rCourse',function (res, data) {
                var category = JSON.parse(data).data;
                Action.send(req,res,'rOptions',{question_id:question_id},function (res, data) {
                    var answer = JSON.parse(data).data;
                    res.render ('pte/question/editquestion',{
                        layout:'pte/layout-pte',
                        active:'editquestion',
                        jscript:'pte/question/editquestion',
                        data:detail,
                        category:category.rows,
                        answer:answer
                    });
                });
            });
        })
    });




//资讯列表
    router.all('/pte/api/inform',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var category_id = req.param('category_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(category_id&&category_id!=' undefined') {
            param.category_id = category_id;
        }
        Action.send(req,res,'rInfo',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });
    router.get('/pte/informlb',function(req,res){
        Action.send(req,res,'rInfo',{},function(res,data) {
            var json=JSON.parse(data);
            var data=json.data;
            Action.send(req,res,'rCategory',{},function(res,data)
            {
                var fenlei = JSON.parse(data).data;
                res.render('pte/inform/informlb', {
                    layout: 'pte/layout-pte',
                    active: 'informlb',
                    jscript: 'pte/inform/informlb',
                    data: data.rows,
                    fellei: fenlei
                })
            })
        })
    });
//增加资讯
    router.get('/pte/add_inform',function(req,res){
        Action.send(req,res,'rCategory',{},function(res,data){
            var json=JSON.parse(data);
            var data=json.data;
            res.render('pte/inform/add_inform', {
                layout: 'pte/layout-pte',
                active: 'add_inform',
                jscript: 'pte/inform/add_inform',
                data:data
            })
        })
    });

//修改资讯
    router.get('/pte/update_inform',function(req,res){
        var info_id = req.param("information_id");
        Action.send(req,res,'rInfo',{info_id:info_id},function (res, data) {
            var json = JSON.parse(data);
            var detail = json.data;
            Action.send(req,res,'rCategory',function (res, data) {
                var json = JSON.parse(data);
                var category = json.data;
                res.render('pte/inform/update_inform', {
                    layout: 'pte/layout-pte',
                    active: 'update_inform',
                    jscript: 'pte/inform/update_inform',
                    data: detail,
                    category: category
                });
            });
        });
    });

//资讯分类


    router.get('/pte/inform_fenlei',function(req,res){
        var category_id = req.param('category_id');
        var param = {category_id:category_id};
        Action.send(req,res,'rCategory',param, function (res, data) {
            var json = JSON.parse(data);
            data = json.data;
            res.render ('pte/inform/inform_fenlei',{
                layout:'pte/layout-pte',
                active:'inform_fenlei',
                jscript:'pte/inform/del_fenlei',
                category_id:category_id,
                data:data
            });
        })

    });
//增加资讯分类
    router.get('/pte/add_fenlei',function(req,res){
        Action.send(req,res,'cCategory',{},function(res,data){
            var json=JSON.parse(data);
            var acts=json.data;
            res.render ('pte/inform/add_fenlei',{
                layout:'pte/layout-pte',
                active:'add_fenlei',
                jscript:'pte/inform/add_fenlei',
                data:data
            })
        })
    });

//修改资讯分类
    router.get('/pte/update_fenlei',function(req,res){
        var category_id = req.param('category_id');
        var param={category_id:category_id};
        Action.send(req,res,'uCategory',param,function(res,data) {
            var json = JSON.parse(data);
            data = json.data;
            res.render('pte/inform/update_fenlei', {
                layout: 'pte/layout-pte',
                active: 'update_fenlei',
                jscript: 'pte/inform/update_fenlei',
                data:data,
                category_id:category_id
                //acts:acts
            });
        })
    });
    //图片轮播
    router.all('/pte/api/pic',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        Action.send(req,res,'rPicture',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })
    });
    router.get('/pte/pic_list',function(req,res){
        Action.send(req,res,'rPicture',{},function(res,data){
            var data = JSON.parse(data).data;
            res.render('pte/picture/pic_list', {
                layout: 'pte/layout-pte',
                active: 'pic_list',
                jscript: 'pte/picture/pic_list',
                data:data.rows
            })
        })
    });
//增加轮播图片
    router.get('/pte/add_pic',function(req,res){
            res.render ('pte/picture/add_pic',{
                layout:'pte/layout-pte',
                active:'add_fenlei',
                jscript:'pte/picture/add_pic',
            })
    });
//认证管理-----获取待审核列表
    router.all('/pte/api/wait_to_renzheng',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var user_name = req.param('user_name');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows,user_name:user_name};

        if(user_name=='') {
            Action.send(req, res, 'rUnCheckCList', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }
        else{
            Action.send(req,res,'searchNameUnChecked',param,function(res,data){
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }
    });
    router.get('/pte/renzheng',function(req,res){
        res.render('pte/renzheng/renzheng', {
            layout: 'pte/layout-pte',
            active: 'renzheng',
            jscript: 'pte/renzheng/renzheng',
        })
    });

    router.get('/pte/renzhenginfo',function(req,res){
        res.render('pte/renzheng/renzhenginfo', {
            layout: 'pte/layout-pte',
            active: 'renzhenginfo',
            jscript: 'pte/renzheng/renzhenginfo',
        })
    });



    //获取证书列表
    router.all('/pte/api/renzhenginfo',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');

        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};

        console.log("param "+param);
        Action.send(req, res, 'rCertificate', param, function (res, data) {
            var json = JSON.parse(data);
            if (json.code == 0) {
                res.status(200).send(JSON.stringify(json));
            } else {
                res.status(200).send(data);
            }
        })


    });


    //获取已审核列表
    router.all('/pte/api/renzheng',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var user_name = req.param('user_name');
        var status = req.param('status');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows,user_name:user_name,status:status};

        console.log("param "+param);
            Action.send(req, res, 'getAuthList', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })


    });
    router.get('/pte/renzheng',function(req,res){
        res.render('pte/renzheng/renzheng', {
            layout: 'pte/layout-pte',
            active: 'renzheng',
            jscript: 'pte/renzheng/renzheng',
        })
    });
    //认证详情
    router.get('/pte/detailrenzheng',function(req,res){
        var id=req.param("id");
        Action.send(req,res,'rCertificateDetails',{id:id},function(res,data){
            var json=JSON.parse(data);
            var data=json.data;

            console.log(data);

            res.render('pte/renzheng/detailrenzheng', {
                layout: 'pte/layout-pte',
                active: 'add_inform',
                jscript: 'pte/renzheng/detailrenzheng',
                data:data
            })
        })
    });


    //证书详情
    router.get('/pte/detailrenzhenginfo',function(req,res){
        var id=req.param("id");
        Action.send(req,res,'rSimpleCertificate',{certificate_id:id},function(res,data){
            var json=JSON.parse(data);
            var data=json.data;

            console.log(data);

            res.render('pte/renzheng/detailrenzhenginfo', {
                layout: 'pte/layout-pte',
                active: 'add_inform',
                jscript: 'pte/renzheng/detailrenzhenginfo',
                data:data
            })
        })
    });

//词条列表
    router.all('/pte/api/citiao_lb',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var content = req.param('content');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(content&&content!='undefined') {
            param.vocabulary = content;
            Action.send(req, res, 'sCitiao', param, function (res, data) {

                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }else {
            Action.send(req, res, 'rCitiao', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }

    });
    router.get('/pte/citiao_lb',function(req,res){
        res.render('pte/citiao/citiao_lb', {
            layout: 'pte/layout-pte',
            active: 'citiao_lb',
            jscript: 'pte/citiao/citiao'
        });
    });
//增加词条
    router.get('/pte/add_citiao',function(req,res){
        res.render('pte/citiao/add_citiao', {
            layout: 'pte/layout-pte',
            active: 'add_citiao',
            jscript: 'pte/citiao/add_citiao'
        });
    });
//修改词条
    router.get('/pte/update_citiao',function(req,res){
        var vocabulary_id=req.param("vocabulary_id");
        var param={vocabulary_id:vocabulary_id};
        Action.send(req,res,'rCitiao',param,function(res,data){

            data=JSON.parse(data);
            res.render('pte/citiao/update_citiao', {
                layout: 'pte/layout-pte',
                active: 'update_citiao',
                jscript: 'pte/citiao/update_citiao',
                vocabulary:data.data,
                vocabulary_id:vocabulary_id
            });
        });
    });


//词条评论管理
    router.all('/pte/api/citiao_pinglun',function(req,res){

        var vocabulary_id = req.param('vocabulary_id');
        var page = req.param('page');
        var rows = req.param('rows');
        var user_id = req.param('user_id');
        if (!page)
            page = 1;
        if (!rows)
            rows = 10;
        var param = {page: page, rows: rows, vocabulary_id:vocabulary_id};
        if(user_id&&user_id!='undefined')
            param.user_id=user_id;
        Action.send(req, res, 'rCitiao_pinglun', param, function (res, data) {
            var json = JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }

        });

    });

    router.get('/pte/citiao_pinglun',function(req,res){
        var vocabulary_id=req.param("vocabulary_id");
        res.render('pte/citiao/citiao_pinglun', {
            layout: 'pte/layout-pte',
            active: 'citiao_pinglun',
            jscript: 'pte/citiao/citiao_pinglun',
            vocabulary_id:vocabulary_id
        });
    });

//用户管理
    router.all('/pte/api/user',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var name = req.param('name');
        //var mobile = req.param('mobile');
        //var sequence = req.param('sequence');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(name&&name!='undefined')
            param.name=name;
        //if(mobile&&mobile!='undefined')
        //    param.mobile=mobile;
        //if(sequence&&sequence!='undefined')
        //    param.sequence=sequence;
        Action.send(req,res,'rUser',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });

    router.get('/pte/user',function(req,res){
        var user_id = req.param('user_id');
        res.render('pte/user/user', {
            layout: 'pte/layout-pte',
            active: 'lecturelist',
            jscript: 'pte/user/user',
            user_id: user_id
        })


    });

//问答列表
    router.all('/pte/api/answer_lb',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var content = req.param('content');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(content&&content!='undefined') {
            param.title = content;
            Action.send(req, res, 'sTrouble', param, function (res, data) {

                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }else{
            Action.send(req, res, 'rTrouble', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }
    });
    router.get('/pte/answer_lb',function(req,res){
        res.render('pte/wendaguanli/wenda_lb', {
            layout: 'pte/layout-pte',
            active: 'wendaguanli_lb',
            jscript: 'pte/wendaguanli/wendaguanli_question'
        });
    });
//专家回复
    router.get('/pte/expert_answer',function(req,res){
        var trouble_id=req.param('trouble_id');
        res.render('pte/wendaguanli/expert_answer', {
            layout: 'pte/layout-pte',
            active: 'expert_answer',
            jscript: 'pte/wendaguanli/expert_answer',
            trouble_id:trouble_id
        });
    });
//回答列表
    router.all('/pte/api/answer',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var content = req.param('content');
        var trouble_id = req.param('trouble_id');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows,trouble_id:trouble_id};
        if(content&&content!='undefined') {
            param.content = content;
            Action.send(req, res, 'sAnswer', param, function (res, data) {

                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }else {
            Action.send(req, res, 'rAnswer', param, function (res, data) {
                var json = JSON.parse(data);
                if (json.code == 0) {
                    res.status(200).send(JSON.stringify(json));
                } else {
                    res.status(200).send(data);
                }
            })
        }

    });
    router.get('/pte/answer',function(req,res){
        var trouble_id = req.param('trouble_id');
        res.render('pte/wendaguanli/answer', {
            layout: 'pte/layout-pte',
            active: 'answer',
            jscript: 'pte/wendaguanli/answer',
            trouble_id:trouble_id
        });
    });





//教师列表
    router.all('/pte/api/teacher_lb',function(req,res){//表格所定义的路径
        var page = req.param('page');
        var rows = req.param('rows');
        var teacher_name=req.param('teacher_name');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(teacher_name&&teacher_name!='undefined')
            param.teacher_name=teacher_name;
        Action.send(req,res,'rTeacher',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })



    })

    router.get('/pte/teacher_lb',function(req,res){//sidemenue对应路径
        res.render('pte/teacher/teacherlb', {
            layout: 'pte/layout-pte',
            active: 'teacher_lb',
            jscript: 'pte/teacher/teacherlb'
        });
    });
//增加教师
    router.get('/pte/add_teacher',function(req,res){
        res.render('pte/teacher/add_teacher', {
            layout: 'pte/layout-pte',
            active: 'add_teacher',
            jscript: 'pte/teacher/add_teacher'
        });
    });
//编辑教师
    router.get('/pte/update_teacher',function(req,res){
        var teacher_id=req.param("teacher_id");
        var param={teacher_id:teacher_id};
        Action.send(req,res,'rTeacher',param,function(res,data){
            data=JSON.parse(data);
            res.render('pte/teacher/update_teacher', {
                layout: 'pte/layout-pte',
                active: 'update_teacher',
                jscript: 'pte/teacher/update_teacher',
                data:data.data.rows[0],
                teacher_id:teacher_id
            });
        });
    });


//案例列表
    router.all('/pte/api/case_lb',function(req,res){
        var page = req.param('page');
        var rows = req.param('rows');
        var title = req.param('title');
        if(!page)
            page=1;
        if(!rows)
            rows=10;
        var param={page:page,rows:rows};
        if(title&&title!='undefined')
            param.title=title;
        Action.send(req,res,'rCase',param,function(res,data){
            var json=JSON.parse(data);
            if(json.code == 0 ){
                res.status(200).send(JSON.stringify(json));
            }else{
                res.status(200).send(data);
            }
        })

    });
    router.get('/pte/case_lb',function(req,res){
        res.render('pte/case/caselb', {
            layout: 'pte/layout-pte',
            active: 'case_lb',
            jscript: 'pte/case/caselb'
        });
    });
//增加案例
    router.get('/pte/add_case',function(req,res) {
        Action.send(req, res, 'rCourseS', {major_id:1}, function (res, data) {
            var json = JSON.parse(data);
            var data = json.data.rows;
            res.render('pte/case/add_case', {
                layout: 'pte/layout-pte',
                active: 'add_case',
                jscript: 'pte/case/add_case',
                data: data
            })
        })
    });


//修改案例
    router.get('/pte/update_case',function(req,res){
        var example_id=req.param("example_id");
        Action.send(req,res,'rCase',{example_id:example_id},function(res,data){
            var json = JSON.parse(data);
            var detail = json.data;
            console.log(detail)
            //案例现在关联的只有课时ID  通过课时ID找出课程下所有课时接口

            Action.send(req,res,'rCourseS',{major_id:1},function (res, data) {
                var json = JSON.parse(data);
                var course = json.data;
                console.log(detail)
                //查出课程下的课时

                //res.status(200).send('aaa');
                //for(var i=0;i<lects.length;i++){
                //    if(lecture_ids.indexOf(lects[i].lecture_id)!=-1)
                //        lects[i].checked=1;
                //}
                res.render('pte/case/update_case', {
                    layout: 'pte/layout-pte',
                    active: 'update_inform',
                    jscript: 'pte/case/update_case',
                    data: detail,
                    course: course.rows
                });
            });
        });
    });

//查看案例详情
    router.get('/pte/detail_case',function(req,res){
        var example_id=req.param("example_id");
        var param={example_id:example_id};
        Action.send(req,res,'rCase',param,function(res,data){
            data=JSON.parse(data);
            res.render('pte/case/detail_case', {
                layout: 'pte/layout-pte',
                active: 'detail_case',
                jscript:'',
                data:data.data.rows[0],
                example_id:example_id
            })
        })
    });

    //专业列表
    router.get('/pte/major',function(req,res){
        res.render('pte/major/major', {
            layout: 'pte/layout-pte',
            active: '',
            jscript:'pte/major/major'
        })
    });
    //专业添加
    router.get('/pte/addmajor',function(req,res){
        res.render('pte/major/addmajor', {
            layout: 'pte/layout-pte',
            active: '',
            jscript:'pte/major/addmajor'
        })
    });

    router.get("/pte/editMajor",function(req,res){

        var msg=req.param("msg");
        var major_id=req.param("major_id");
        Action.send(req,res,'getMajor',{id:major_id},function(res,data){

            var host=req.headers["host"];
            if(host.indexOf("zjadmin")!=-1)//server
                var uploadPath="http://121.40.55.132:8082"+httpconf.root+"/question/uploadFinalQuestion?major_id="+major_id;
            else
                var uploadPath="http://127.0.0.1:8080"+httpconf.root+"/question/uploadFinalQuestion?major_id="+major_id;
            var major=JSON.parse(data).data;
            res.render('pte/major/editmajor', {
                layout: 'pte/layout-pte',
                active: '',
                jscript:'pte/major/editmajor',
                uploadPath:uploadPath,
                msg:msg,
                major:major
            })
        })
    })

    router.get("/pte/genInviteCode",function(req,res){

        res.render('pte/code/genInviteCode', {
            layout: 'pte/layout-pte',
            active: '',
            jscript:'pte/code/genInvite'
        })
    });

    router.get("/pte/inviteList",function(req,res){

        res.render('pte/code/inviteList', {
            layout: 'pte/layout-pte',
            active: '',
            jscript:'pte/code/inviteList'
        })
    });
}